//
//  WzzZdyTaBar.m
//  Wb_oc
//
//  Created by wzz on 16/7/28.
//  Copyright © 2016年 wzz. All rights reserved.
//

#import "WzzZdyTaBar.h"

@interface WzzZdyTaBar()
@property (nonatomic , strong) UIButton * zdyBut;

@end
@implementation WzzZdyTaBar


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}


- (void)setupUI{
    [self addSubview:self.zdyBut];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat ww = self.frame.size.width * 0.2;
    __block CGFloat index = 0;
    
    //遍历
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if ([obj isKindOfClass:[NSClassFromString(@"UITabBarButton") class]]) {
            obj.frame = CGRectMake(ww *index, 0, ww, self.frame.size.height);
            index++;
            
            if (index == 2) {
                index++;
            }
        }
    }];
    
    self.zdyBut.center = CGPointMake(self.frame.size.width * 0.5, self.frame.size.height * 0.5);

    
}

- (void)onClickAddBut{
    if (_centerButBlock) {
        _centerButBlock();
    }
}

- (UIButton *)zdyBut{
    if (_zdyBut == nil) {
        
        _zdyBut = [[UIButton alloc]init];
        [_zdyBut setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [_zdyBut setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        [_zdyBut setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [_zdyBut setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        [_zdyBut addTarget:self action:@selector(onClickAddBut) forControlEvents:UIControlEventTouchUpInside];
        
        [_zdyBut sizeToFit];
    }
    return  _zdyBut;
}
@end
